<?php

!defined('IN_NOVA') && exit('Access Denied!');

class Welcome {

	public function start() {
		global $user,$cache;
		@header("content-type: text/html; charset=utf-8");
?>

<style>
.admin_panel {
	width:460px;
}
</style>

<div id="left" style="float:left;">

	<div class="admin_panel">
		<div class="admin_title">等待处理</div>
		<div class="admin_content">
		 	<div style="text-align:left;line-height:20px;">
		 		<?php
		 		$message = array();
		 		if( str_replace( APP_ROOT, '', APP_ADMIN ) == 'admin/' ) {
		 			$message[] = '强烈建议您重命名后台管理目录 [<a href="#" onclick="ajax_load(\'' . ADMIN_PATH . '\',\'help\');return false;">帮助</a>]';
		 		}
		 		if( !defined( 'SUPER_PASSWORD' ) || SUPER_PASSWORD == '' ) {
		 			$message[] = '强烈建议您开启管理员超级密码功能 [<a href="#" onclick="ajax_load(\'' . ADMIN_PATH . '\',\'help\');return false;">帮助</a>]';
		 		}
		 		if( count( $message ) ) {
		 			echo '<font color="red">安全提示</font>: <ol style="margin-left:20px;">';
		 			foreach( $message as $msg ) {
		 				echo '<li>' . $msg . '</li>';
		 			}
		 			echo '</ol>';
		 		}
		 		?>
				<br/>待审核评论: <?php echo $cache->count['comment_num_censor'] ?> 条
				<br/>待审核留言: <?php echo $cache->count['guestbook_num_censor'] ?> 条
			</div>
		</div>
	</div>

	<div class = "admin_panel">
		<div class = "admin_title">最新评论</div>
		<div class = "admin_content">
			<div style="text-align:left;line-height:20px;">
			<ol style="padding-left:20px;">
			<?php
				if( $cache->comment_new == NULL ) {
					global $db;
					$cache->set( 'comment_new', $db->fetch_all( 'SELECT C.cid,C.comment, C.articleid, A.type, A.address, A.category, A.title, C.author FROM `' . DB_PREFIX . 'comment` as C, `' . DB_PREFIX . 'article` as A WHERE C.articleid=A.id and C.isdel=0 and C.isshow=1 and A.isdel=0 ORDER BY C.cid DESC limit 0,10' ), 0 );
				}
				foreach ( $cache->comment_new as $row ) {
					if( $row['address'] == '' ) $row['address'] = $row['articleid'];
					if( $cache->config['arttype'] == '动态' ){
						echo '<li><a href="' . APP_PATH . 'index.php?m=article&p=' . $row['articleid'] . '#comment-' . $row['cid'] . '" title="[' . $row['author'] . '] 发表在 [' . strip_tags( $row['title'] ) . ']">' . cut_str( str_replace( '<br />', ' ', $row['comment'] ), 60 ) . '</a></li>';
					} else {
						echo '<li><a href="' . APP_PATH . 'article/' . $cache->category[$row['category']]['alias'] . '/' . $row['address'] . '.html#comment-' . $row['cid'] . '" title="[' . $row['author'] . '] 发表在 [' . strip_tags( $row['title'] ) . ']">' . cut_str( str_replace( '<br />', ' ', $row['comment'] ), 60 ) . '</a></li>';
					}
				}
			?>
			</ol>
			</div>
		</div>
	</div>

</div>

<div style="float:right;" align="right">

	<div class="admin_panel">
		<div class="admin_title">博客信息</div>
		<div class="admin_content">
		 	<div style="text-align:left;line-height:20px;">
				日志数量: <?php echo $cache->count['article_num'] ?> 篇
				<br/>评论数量: <?php echo $cache->count['comment_num'] ?> 条
				<br/>留言数量: <?php echo $cache->count['guestbook_num'] ?> 条
				<br/><?php echo $cache->menu['laodao']['title']; ?>数量: <?php echo $cache->count['laodao_num'] ?> 条
				<br/>附件数量: <?php echo $cache->count['file_num'] ?> 个
			</div>
		</div>
	</div>

	<div class="admin_panel">
		<div class="admin_title">系统信息</div>
		<div class="admin_content">
		 	<div style="text-align:left;line-height:20px;">
		 		空间占用: <?php echo round( $this->countDirSize( '../' )/(1024*1024), 2 ) . ' MB' ?>
				<br/>物理路径: <?php echo APP_ROOT ?>
				<br/>脚本超时: <?php echo get_cfg_var('max_execution_time') ?> 秒
				<br/>PHP版本: <?php echo PHP_VERSION ?>
				<br/>MySQL版本: <?php echo mysql_get_server_info() ?>
				<br/>服务器软件: <?php echo $_SERVER['SERVER_SOFTWARE'] ?>
			</div>
		</div>
	</div>

	<div class="admin_panel" style="float:right;">
		<div class="admin_title">感谢</div>
		<div class="admin_content">
			<div style="padding:5px;clear:both;font-size:12px;text-align:left;line-height:20px;">
				在开发过程中受益于 JQuery、KindEditor、PHPMailer、WordPress、Habari、PJBlog 与 JBlog 项目。
				<br/>谨向这些项目的开发者表示感谢，并致以由衷的敬意。
			</div>
		</div>
	</div>

</div>

<div class="fixed"></div>
<?php
	}

	private function countDirSize( $dir )
	{
		$sizeResult = 0;
		$handle = opendir( $dir );
		while ( false !== ( $FolderOrFile = readdir( $handle ) ) ) {
			if( $FolderOrFile != "." && $FolderOrFile != ".." ) {
				if( is_dir( "$dir/$FolderOrFile" ) ) {
					$sizeResult += $this->countDirSize("$dir/$FolderOrFile");
				} else {
					$sizeResult += filesize("$dir/$FolderOrFile");
				}
			} 
		}
		closedir($handle);
		return $sizeResult;
	}

}
?>
